package com.jadesoft.common.rp;

import java.util.ArrayList;
import java.util.List;

import com.jadesoft.common.service.PaginationService;
import com.jadesoft.common.util.Constants;

public class JadeBSImpl implements JadeBS {
	private PaginationService persistence = new PaginationService();
	/**
	 * @param className    需要查找的CLASS类型
	 * @param propertyName 需要比较的属性名
	 * @param enterId	       企业ID
	 * @param curNo		       当前编号
	 * @param type	                 需要查找的类型
	 */
	public String findAdjacentNo(String className, String propertyName,
			Integer enterId, String curNo, String type) {
		String compareType = Constants.NEXT_BILL.equals(type) ? " > " : " < ";
		String orderType = Constants.NEXT_BILL.equals(type) ? " asc " : " desc ";
		String hql = " SELECT obj." + propertyName  
					+ " FROM " + className + " obj "
					+ " WHERE obj.enterId = ? "
					+ " AND  obj."+ propertyName + compareType + " ? " 
					+ " ORDER BY obj."+ propertyName + orderType 
					+ " limit` 1 ";
		System.out.println(hql);
		List params = new ArrayList();
		params.add(enterId);
		params.add(curNo);
		Object obj = persistence.query(hql,params.toArray());
		return obj.toString();
	}
	
	public static void main(String[] args) {
		JadeBSImpl impl = new JadeBSImpl();
		System.out.println(impl.findAdjacentNo("PurchaseWarehousing", "no",1, "JH10120009", "next"));
		
	}

}
